package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private TextView selectedCityTv;
    private Button selectCityBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();

    }
    private void initView(){
        selectedCityTv = findViewById(R.id.city_select_tv);
        selectCityBtn = findViewById(R.id.city_select_btn);
    } private void initData(){

    } private void initEvent(){
        selectCityBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(MainActivity.this,CitySelectActivity.class);
                startActivityForResult(intent,1);
            }


        });
    }
    protected void onActivityResult(int requestCode,int resultCode,Intent data) {
        super.onActivityResult(requestCode,resultCode,data);
        if (requestCode == 1 && requestCode == 1){
            String cityName =data.getStringExtra("data");
            selectedCityTv.setText(cityName+"");
            Toast.makeText(this, cityName+"", Toast.LENGTH_SHORT).show();

        }

    }
}
